package com.song.eduservice.controller;


import com.song.commonutils.ResultObj;
import com.song.eduservice.entity.subject.OneSubject;
import com.song.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author song
 * @since 2020-03-29
 */
@RestController
@RequestMapping("/eduservice/subject")
@Api(description = "课程分类管理")
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    /***
     * 添加课程分类
     * @param file
     * @return
     */
    //获取上传过来的文件，把文件内容读取出来

    @ApiOperation(value = "excel导入课程")
    @PostMapping("/")
    public ResultObj addSubject(MultipartFile file){
        try {
            eduSubjectService.saveSubject(file,eduSubjectService);
            return ResultObj.ADD_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.ADD_ERROR;
        }

    }

    /**
     * 查询所有课程（树形）
     * @return
     */
    @ApiOperation(value = "查询所有课程")
    @GetMapping("/")
    public ResultObj findAllSubject(){
        List<OneSubject> list = eduSubjectService.findAllSubject();
        return ResultObj.ok().data("data",list);
    }

}

